package study.javaee.practice.service;

import study.javaee.practice.dao.JpaMd5userDAO;
import study.javaee.practice.entity.JpaMd5user;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class JpaMd5userservice {
    @Autowired
    JpaMd5userDAO md5userDAO;

    public boolean isExist(String username) {
        JpaMd5user user = getByName(username);
        return null!=user;
    }

    public JpaMd5user getById(int id){
        return md5userDAO.findById(id);
    }
    public JpaMd5user getByName(String username) {
        return md5userDAO.findByName(username);
    }

    public JpaMd5user getbynameandpassword(String username, String password){
        return md5userDAO.getByNameAndPassword(username, password);
    }

    public JpaMd5user getbyemailandpassword(String email, String password){
        return md5userDAO.getByEmailAndPassword(email, password);
    }

    public void add(JpaMd5user user) {
        md5userDAO.save(user);
    }
}
